package com.atguigu.mvc.filter;

import javax.servlet.*;
import java.io.IOException;

public class EncodingFilter implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("EncodingFilter init  filterConfig = " + filterConfig);
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("EncodingFilter doFilter " );

        response.setContentType("text/html;charset=utf-8");


        // response.setHeader("Content-Type", "text/html;charset=utf-8");  // 解放响应乱码

        chain.doFilter(request, response);
    }

    public void destroy() {
        System.out.println("EncodingFilter destroy " );
    }
}
